import  http from "@/common/js/http.js";
import {calcDistance,distanceToStr} from "@/common/js/map.js";
import storex from "@/store/index.js" 
function setDefaultCurStore(){
	let location = storex.getters['user/location']
	console.log	("==location==",location)
	let _store=null,minDis=10000
	http.get("meet.store/getListByCityName",{cityName:location.city_name}).then(res=>{
		if(res.status){
			let storeList = res.data
			storeList.forEach(store=>{
				let d = calcDistance(
					{latitude:store.latitude,longitude:store.longitude},
					{latitude:location.latitude,longitude:location.longitude}
				)
				if	(d<minDis){
					_store=store
					_store.distance=d
					_store.distanceStr=distanceToStr(d)
				}
			})
			if(_store!==null)storex.commit("user/cur_store",_store)
		}
	})
}
export {
	setDefaultCurStore
}